package branchandbound;

import java.util.*;
import java.util.function.Consumer;

/**
 * @author MtRider
 * @version 1.0
 * @description 田忌赛马
 * @GiteeAndGithub MtRider
 * @date 2022/5/5 21:52
 */
public class TianRacing {
    public static void main(String[] args) {

        horseRace();

    }

    /**
     * 田忌赛马
     */
    private static void horseRace() {
        Scanner input = new Scanner(System.in);
        List<Integer> tianList = new ArrayList<>();
        List<Integer> qiList = new ArrayList<>();
        //统一存放每场输赢金币并输出
        List<Integer> moneyList = new ArrayList<>();
        while (true) {
            //获取马数
            int horseNum = input.nextInt();
            input.nextLine();
            //输入马数为0直接结束
            if (horseNum == 0) {
                break;
            }

            //获取田忌的马的速度
            String[] tianHorseSpeed = input.nextLine().split(" ");
            //获取齐威王妈的速度
            String[] qiHorseSpeed = input.nextLine().split(" ");

            //马的速度类型转换放入list中
            for (int i = 0; i < horseNum; i++) {
                tianList.add(Integer.parseInt(tianHorseSpeed[i]));
                qiList.add(Integer.parseInt(qiHorseSpeed[i]));
            }

            //排序
            Collections.sort(tianList);
            Collections.sort(qiList);

            //田忌初始金币
            int tianMoney = 0;
            int i = 0, j = 0, x = horseNum - 1, y = horseNum - 1;
            boolean tianLast = true;


            while (tianLast) {
                //是否是最后一匹马
                if (x == i) {
                    tianLast = false;
                }

                //如果田忌当前最好的马可以胜齐王最好的马，那么比一场
                if (tianList.get(x) > qiList.get(y)) {
                    x--;
                    y--;
                    tianMoney += 200;
                }
                //如果田忌当前最差的马可以胜齐王最差的马，那么比一场
                else if (tianList.get(i) > qiList.get(j)) {
                    i++;
                    j++;
                    tianMoney += 200;
                }
                //否则，让田忌最差的马和齐王最好的好比一场
                else {
                    if (tianList.get(i) < qiList.get(y)) {
                        tianMoney -= 200;
                    }
                    i++;
                    y--;
                }

            }
            moneyList.add(tianMoney);
            tianList.clear();
            qiList.clear();
        }
        //输出结果
        moneyList.forEach(System.out::println);
    }
}
